
import { Controller, Get, Post, Put, Body, Query, Param, Delete } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { RequirePermission } from 'src/common/decorators/require-premission.decorator';
import { CourseService } from './course.service';
import { CreateCourseDto, BaseCourseDto, UpdateCourseDto, QueryCourseDto, ListCourseDto } from './dto/course.dto';
import { ApiDataResponse } from 'src/common/decorators/apiDataResponse.decorator';
import { UserTool, UserToolType } from 'src/module/system/user/user.decorator';
import { RepeatSubmit } from 'src/common/decorators/repeat-submit.decorator';

@ApiTags('课程')
@Controller('edutation/course')
export class CourseController {
  constructor(private readonly courseService: CourseService) {}
  @ApiOperation({ summary: '课程-创建',  })
  @ApiDataResponse(BaseCourseDto)
  @RequirePermission('edutation:course:add')
  @Post()
  @RepeatSubmit()
  create(@Body() body: CreateCourseDto,@UserTool() { injectCreate }: UserToolType) {
    return this.courseService.create(injectCreate(body));
  }


  @ApiOperation({ summary: '课程-列表',  })
  @ApiDataResponse(ListCourseDto, true, true)
  @RequirePermission('edutation:course:list')
  @Get('list')
  findAll(@Query() query: QueryCourseDto) {
    return this.courseService.findAll(query);
  }


  @ApiOperation({  summary: '课程-详情',    })
  @ApiDataResponse(BaseCourseDto)
  @RequirePermission('edutation:course:query')
  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.courseService.findOne(+id);
  }


  @ApiOperation({ summary: '课程-修改',  })
  @ApiDataResponse()
  @RequirePermission('edutation:course:edit')
  @Put()
  @RepeatSubmit()
  update(@Body() body: UpdateCourseDto,@UserTool() { injectUpdate }: UserToolType) {
    return this.courseService.update(injectUpdate(body));
  }


  @ApiOperation({  summary: '课程-删除', })
  @ApiDataResponse()
  @RequirePermission('edutation:course:remove')
  @Delete(':ids')
  remove(@Param('ids') ids: string) {
    const courseIdList = ids.split(',').map((id) => +id);
    return this.courseService.remove(courseIdList);
  }
}
